package com.heiyu.utils;

import com.google.common.collect.Maps;

import java.util.Map;

/**
 * Created by mountain on 18/6/13.
 */
public class PageUtils {

    public static Map<String,Object> newParam(Integer pageIndex,Integer pageSize){
        Map<String,Object> map  = Maps.newHashMap();
        pageSize = pageSize==null?20:pageSize;
        map.put("offset",pageSize);
        pageIndex = pageIndex==null?0:(pageIndex-1);
        if(pageIndex<0){
            pageIndex = 0;
        }
        map.put("index",pageIndex*pageSize);
        return map;
    }

    public static Map<String,Object> adminNewParam(Integer pageIndex,Integer pageSize){
        Map<String,Object> map  = Maps.newHashMap();
        pageSize = pageSize==null?20:pageSize;
        map.put("offset",pageSize);
        pageIndex = pageIndex==null?1:(pageIndex-1);
        if(pageIndex<1){
            pageIndex = 1;
        }
        map.put("index",pageIndex*pageSize);
        return map;
    }
}
